package org.jeecg.modules.demo.ysd.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.demo.ysd.entity.YsdMedicalMap;
import org.jeecg.modules.demo.ysd.entity.YsdMedicalMapVo;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @Description: 就医地图
 * @Author: jeecg-boot
 * @Date:   2025-06-24
 * @Version: V1.0
 */
public interface YsdMedicalMapMapper2 extends BaseMapper<YsdMedicalMap> {


    @Select("""
        SELECT 
            id, create_by, create_time, province, city,district,name,location,hospital_name,expert,clinic,registration_fee
    ,insurance,lng,lat,remartk,
            (6371 * ACOS(
                COS(RADIANS(#{latitude})) * 
                COS(RADIANS(lat)) * 
                COS(RADIANS(lng) - RADIANS(#{longitude})) + 
                SIN(RADIANS(#{latitude})) * 
                SIN(RADIANS(lat))
            )) as distance
        FROM ysd_medical_map
        where name like  #{name}
        ORDER BY 
        distance asc
        LIMIT #{offset}, #{size}
        """)
    List<YsdMedicalMapVo> selectNearby(
            @Param("lat") Double latitude,
            @Param("lng") Double longitude,
            @Param("offset") long offset,
            @Param("size") long size,
            @Param("name")  String name);

}
